import jdk.nashorn.api.scripting.AbstractJSObject;

public class GoodManager {
    private GoodGroup[] goodList;

    public GoodManager() {
    }

    public GoodManager(GoodGroup[] goodList) {
        this.goodList = goodList;
    }

    public GoodGroup[] getGoodList() {
        return goodList;
    }

    public void setGoodList(GoodGroup[] goodList) {
        this.goodList = goodList;
    }
    public GoodGroup findByName(String name){
        for(GoodGroup goodsGroup:goodList){
            for(Goods g:goodsGroup.getMember())
                if(g.getName().equals(name))
                    return goodsGroup;
        }
        return null;
    }
    public void add(Goods goods){
        GoodGroup goodsGroup;
        if(findByName(goods.getName())!=null)
            System.out.println("该货物已存在");
        else{
            for(int i=0;i<goodList.length;i++){
                if(goodList[i]==null){
                    goodsGroup=new GoodGroup();
                    goodsGroup.setCatory(goods.getName());
                    goodsGroup.setMember(new Goods[]{goods});
                    goodList[i]=goodsGroup;
                }
            }
        }
    }
    public void add(Goods[] goods){
        for(Goods g:goods)
            add(g);
    }
}

